#ifndef BLLDATAFLOW_H
#define BLLDATAFLOW_H

#include <QObject>
#include <QMutex>
#include <QThread>
#include <QDebug>
#include <QPrinter>
#include "ettadatastruct.h"
#include "myoffice.h"
#include "QDateTime"

class BllDataFlow : public QObject
{
    Q_OBJECT

public:
    static BllDataFlow * getInstance();
    void returnLastMainPage();
    void changeMainPageIndex(int index);
    void changeConfigPageIndex(int index);
    void changeExperimentPageIndex(int index);
    void changeAboutPageIndex(int index);
    void changeSystemConfigPageIndex(int index);
    void changeFactoryConfigPageIndex(int index);
    void changeDataPageIndex(int index);
    void showReportPage(const ExperimentInfo &expInfo);
    void setUserStatusText(QString username);
    void showAllParameters(bool scrollToBottom = false);
    void loadEnabledParamters();
    void setWidgetVisible(int permission);
    void showAllUsers(bool scrollToBottom = false);
    void showAllRoles(bool scrollToBottom = false);
    void updateVoltTestResult(VoltTest vt);
    void updateFlowTestResult(FlowTest st);
    void insertExpInfo(const ExperimentInfo &expInfo);
    void updateExpPassInfo(const ExperimentInfo &expInfo);
    void updateExpFailInfo(const ExperimentInfo &expInfo, const HostReply &error,int errortype);
    void setLineEditRoleName(QString name);
    void updatePermissionListWidget(int permission);
    void sendDeletedRole(Role role);
    void sendModifyRoleUser(User user);
    void sendResetPwUser(User user);
    void sendDeleteUser(User user);
    void sendModifyParameter(Parameter p);
    void sendDeleteParameter(Parameter p);
    void setPowerOffEnable(bool state);
    void generateAllHtml(int type, const QString contentHtml);
    void savePdf(int type, const QString fileName, const QString contentHtml);
    void retranslateUi();
    void selectDateTimePicker(QDateTime dateTime, QString whatsThis);
    void buildFinished();
    void logout();
    void changePwDone();
    void endExperiment(bool state);
    //void returnMain(bool state);
    void setCurrentTime(int);

signals:
    void returnLastMainPageSignal();
    void changeMainPageIndexSignal(int);
    void changeConfigPageIndexSignal(int);
    void changeExperimentPageIndexSignal(int);
    void changeAboutPageIndexSignal(int);
    void changeSystemConfigPageIndexSignal(int);
    void changeFactoryConfigPageIndexSignal(int);
    void changeDataPageIndexSignal(int);
    void showReportPageSignal(const ExperimentInfo &);
    void setUserStatusTextSignal(QString);
    void showAllParametersSignal(bool scrollToBottom);
    void loadEnabledParamtersSignal();
    void setWidgetVisibleSignal(int);
    void showAllUsersSignal(bool scrollToBottom);
    void showAllRolesSignal(bool scrollToBottom);
    void updateVoltTestResultSignal(VoltTest);
    void updateFlowTestResultSignal(FlowTest);
    void insertExpInfoSignal(const ExperimentInfo &expInfo);
    void updateExpPassInfoSignal(const ExperimentInfo &expInfo);
    void updateExpFailInfoSignal(const ExperimentInfo &expInfo, const HostReply &error, int errortype);
    void setLineEditRoleNameSignal(QString);
    void updatePermissionListWidgetSignal(int);
    void sendDeletedRoleSignal(Role);
    void sendModifyRoleUserSignal(User);
    void sendResetPwUserSignal(User);
    void sendDeleteUserSignal(User);
    void sendModifyParameterSignal(Parameter);
    void sendDeleteParameterSignal(Parameter);
    void generateAllHtmlSignal(int type, const QString contentHtml);
    void generateAllHtmlSucceedSignal(int type, const QString allHtml);
    void savePdfSignal(int type, const QString fileName, const QString contentHtml);
    void savePdfSucceedSignal(int type);
    void updatePrintParamSignal();
    void setPowerOffEnableSignal(bool state);
    void retranslateUiSignal();
    void selectDateTimePickerSignal(QDateTime dateTime, QString whatsThis);
    void buildFinishedSignal();
    void logoutSignal();
    void changePwDoneSignal();
    void endExperimentSignal(bool state);
    //void returnMainSignal(bool state);
    void setCurrentTimeSignal(int);
    void hostVersionSignal(const QString &);
    void liquidDetectedSignal();
    void updateLocalInfo();

private:
    void initRegExpValidator();

private:
    explicit BllDataFlow(QObject *parent = nullptr);
    static BllDataFlow * instance;
    QThread * myofficeThread;
    MyOffice * myoffice;

};

#endif // BLLDATAFLOW_H
